<template>
  <swiper
    class="swiper"
    :options="swiperOption"
    ref="mySwiper"
    v-if="swiperList.length > 0"
  >
    <swiper-slide v-for="item in swiperList" :key="item.public_id">
      <img :src="item.icon_url" :alt="item.public_name">
    </swiper-slide>

    <div class="swiper-pagination" slot="pagination"></div>
  </swiper>
</template>

<script>
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
export default {
  name: 'BannerSwiper',
  props: {
    swiperList: {
      type: Array,
      default: () => []
    }
  },
  data () {
    return {
      swiperOption: {
        // 进来就加载
        notNextTick: true,
        pagination: {
          el: '.swiper-pagination'
        },
        loop: true,
        // 配置自动播放
        autoplay: {
          delay: 3000,
          // 最后一个是否停止
          stopOnLastSlide: false,
          // 用户操作swiper之后，是否禁止autoplay
          disableOnInteraction: false
        },
        observer: true,
        observeParents: true,
        // 配置速度
        speed: 600,
        // 滑动后回调函数
        on: {
          slideChangeTransitionEnd () {
          }
          //   preventLinksPropagation: false
        }
      }
    }
  },
  computed: {
    // 拿到swiper对象
    swiper () {
      return this.$refs.mySwiper.swiper
    }
  },
  components: {
    Swiper,
    SwiperSlide
  }
}

</script>
<style lang='scss' scoped>
.swiper {
  padding-top: px2rem(59);
  width: 95%;
  border-radius: px2rem(20);
  img {
    @include setWH(100%, 100%);
  }
}
/*
穿透修改样式
*/
.swiper /deep/ .swiper-pagination-bullet-active {
  background-color: #f5f5f5;
}
.swiper /deep/ .swiper-pagination-bullet {
  @include setWH(px2rem(6), px2rem(6));
  border-radius: 0;
}
</style>
